package com.xyzwps.collections.tree;

import com.xyzwps.collections.NotImplementedException;

import java.util.Comparator;
import java.util.Objects;

public class RedBlackTree<C> {

    private final Comparator<C> comparator;

    RedBlackTree(Comparator<C> comparator) {
        this.comparator = comparator;
    }

    RedBlackTree() {
        this(null);
    }


    public void add(C e) {
        this.checkElement(e);
        // TODO:
    }

    public boolean contains(C e) {
        throw new NotImplementedException("TODO:");
    }

    public void remove(C e) {
        throw new NotImplementedException("TODO:");
    }

    private void checkElement(C e) {
        Objects.requireNonNull(e);
        if (comparator == null && e instanceof Comparable) {
            throw new IllegalArgumentException("Element should be Comparable");
        }
    }

    @SuppressWarnings("unchecked")
    private int compare(C e1, C e2) {
        if (comparator != null) return comparator.compare(e1, e2);
        return ((Comparable<C>) e1).compareTo(e2);
    }
}

